/*
 * @Author: wuqingchun
 * @Date: 2024-10-15 19:58:21
 * @Description: 
 * @LastEditors: wuqingchun
 * @LastEditTime: 2024-10-15 19:58:25
 */
#include <mutex>
#include <queue>
#include <condition_variable>

template <typename T>
class CBlockQueue
{
private:
    /* data */
    std::queue<T> m_Queue;
    std::condition_variable m_Cond;
    std::mutex m_Mutex;

public:
    CBlockQueue(/* args */)
    {

    }

    ~CBlockQueue()
    {

    }

    void push(const T& refElem)
    {
        std::unique_lock<std::mutex> ulk(m_Mutex);
        m_Queue.push(refElem);
        m_Cond.notify_all();
    }

    void push(T&& refElem)
    {
        std::unique_lock<std::mutex> ulk(m_Mutex);
        m_Queue.push(refElem);
        m_Cond.notify_all();
    }

    T pop()
    {
        std::unique_lock<std::mutex> ulk(m_Mutex);
        while (m_Queue.size() == 0)
        {
            m_Cond.wait(ulk);
        }

        T Elem(std::move(m_Queue.front()));
        m_Queue.pop();
        return std::move(Elem);//move ??
    }

    size_t size()
    {
        std::unique_lock<std::mutex> lg(m_Mutex);
        return m_Queue.size();
    }
};